-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add support for context-only resources (#1405) #1406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
dcad00e to
cbcdec5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @0Delta thank you for this contribution - are you running into this limitation with a concrete application you're trying to implement? If so would you be able to provide some additional details as a motivating example for this change?
|
Hi @felixweinberger. from mcp.server.fastmcp import Context, FastMCP
mcp = FastMCP()
@mcp.resource("resource://user_profile")
def get_user_profile(ctx: Context) -> str:
ctx.info("Fetching user profile")
return "Profile data for user..."When I tried to display this in Inspector, Inspector mistakenly thought it needed arguments and wouldn't run.
|
|
This resource should be recognized as just a Resource, not a template, right? |
cbcdec5 to
392e6b4
Compare
392e6b4 to
4346b24
Compare
|
@felixweinberger |
Add support for context-only resources (modelcontextprotocol#1406)

Add support for context-only resources
Motivation and Context
#1405
Currently, it is not possible to define a Resource that takes only the Context parameter as an argument. When attempting to create such a resource, the registration logic incorrectly classifies it as a template resource instead of a regular resource.
This limitation prevents developers from creating resources that need access to server session context but don't require dynamic URI components, reducing flexibility in resource design.
How Has This Been Tested?
Breaking Changes
No breaking changes. The
contextparameter inResource.read()method is optional with defaultNone. All existing resource implementations continue to work unchanged.Types of changes
Checklist
Additional context